﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using cecbData;
using cecbClasses.Data_Adapters;
namespace CECB
{
    /// <summary>
    /// Interaction logic for Team_Window.xaml
    /// </summary>
    public partial class Team_Window : Window
    {
        public Team_Window()
        {
            InitializeComponent();
            listBox1.ItemsSource = new cecbClasses.Data_Adapters.Member.Func_Members().getConsultents();
            combobox_TeamLeader.ItemsSource = new cecbClasses.Data_Adapters.Func_ProjectTeams().getTeamLeaders();
        }

        private void button_Save_Member_Click(object sender, RoutedEventArgs e)
        {
           
        }

        private void button_Save_Cancel_Click(object sender, RoutedEventArgs e)
        {

        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            //String memberId = combobox_TeamLeader.SelectedValue.ToString();

            //int size = listBox1.Items.Count;
            //List<Employee> list = new List<Employee>();
            //foreach (Employee s in listBox1.SelectedItems)
            //{
            //    list.Add(s);
            //}

            //Dss.Methods.ProjectTeam ptm = new Dss.Methods.ProjectTeam();
            //ptm.InsertProjectTeam(textBox_FirstName.Text.Trim(), list , memberId);

            if (textBox_FirstName.Text.Length == 0)
            {
                MessageBox.Show("Enter Team Name", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else if (combobox_TeamLeader.SelectedIndex == -1)
            {
                MessageBox.Show("Select Team Leader", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                String memberId = combobox_TeamLeader.SelectedValue.ToString();

                int size = listBox1.Items.Count;
                List<Members> list = new List<Members>();
                foreach (Members s in listBox1.SelectedItems)
                {
                    list.Add(s);
                }

                cecbClasses.Data_Adapters.Func_ProjectTeams ptm = new cecbClasses.Data_Adapters.Func_ProjectTeams();
                ptm.InsertProjectTeam(textBox_FirstName.Text.Trim(), list, memberId);

                MessageBox.Show("Team Created Successfully", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                clear();
            }

        }

        public void clear() 
        {
            textBox_FirstName.Clear();
            combobox_TeamLeader.SelectedIndex = -1;
            listBox1.ItemsSource = null;
            listBox1.Items.Clear();
        }

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }
    }
}
